load c:\manoj\projects\plasma\HUA_PIU1.mat
load c:\manoj\projects\ace\substorm;
%load c:\manoj\projects\ace\rand_substorm;
load c:\manoj\projects\substorm\selected_substorm selected_substorm;
fday_substorm = selected_substorm;
%day
st = 14/24;
en = 20/24;
% night
% st = 3/24;
% en = 7/24;
% 

mean_hua = nanmean(HUAPIU);
i_counter=0;
radius_epoch = 1/24;

for i = 1:length(fday_substorm),
    
    
    if fday_substorm(i)-floor(fday_substorm(i)) > st & ...
            fday_substorm(i)-floor(fday_substorm(i)) < en,
        
       [fday_int,ii] = intersect(HUA_PIU_fday,floor(fday_substorm(i)));
       
       if ~isempty(fday_int),
          fday_frac = HUA_PIU_fday(ii)+magnetic_frac;
           if fday_frac(1) < fday_substorm(i)-radius_epoch & ...
               fday_frac(end) > fday_substorm(i)+radius_epoch,
                     i_counter = i_counter+1;
           
           L = fday_frac > fday_substorm(i)-radius_epoch & ...
               fday_frac < fday_substorm(i)+radius_epoch;
           
           if sum(L) > floor(radius_epoch*2*1440),
               kkk = find(L ==1);
               L(kkk(1)) = 0;
           end;
           HUAPIU(ii,:)= HUAPIU(ii,:)-mean_hua;
           SEG_HUA(i_counter,:) = HUAPIU(ii,L);
           end;
           
           end;
       end;
    end;
    plot(-radius_epoch*1440+0.5:radius_epoch*1440-0.5,nanmean(SEG_HUA));

